//
//  MasterDetailViewController.m
//  TextApplication
//
//  Created by dllo on 16/9/4.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "MasterDetailViewController.h"
#import "TAMacro.h"
#import "ZWYNetTool.h"
#import "MasterDetailModel.h"
#import "UIImageView+WebCache.h"
#import "TopCollectionViewCell.h"
#import "RecommendCollectionViewCell.h" // 推荐
#import "GoodsViewController.h"
#import "LoverCollectionViewCell.h"
#import "LoverModel.h"
#import "ConcernModel.h"
#import "GoodsModel.h"
#import "LikeDetailViewController.h"

#import "MBProgressHUD.h"
#import "MJRefresh.h"
#import "TextView.h"

@interface MasterDetailViewController () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIImageView *picImageView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *jobLabel;

@property (nonatomic, strong) NSMutableArray *topArray;

@property (nonatomic, strong) NSArray *topcollectArray;
@property (nonatomic, strong) NSArray *segArray;
@property (nonatomic, strong) UISegmentedControl *segment;
@property (nonatomic, strong) UICollectionView *topCollectionView;

@property (nonatomic, strong) UICollectionView *RecommendCollectionView;

@property (nonatomic, strong) NSMutableArray *indexArray;
@property (nonatomic, strong) NSMutableArray *secIdexArray;
@property (nonatomic, strong) NSMutableArray *recommandArray;

@property (nonatomic, strong) UIScrollView *backScrollView;
@property (nonatomic, strong) UICollectionView *concernCollectionView;
@property (nonatomic, strong) NSMutableArray *concernArray;
@property (nonatomic, strong) UICollectionView *likeCollectionView;
@property (nonatomic, strong) NSMutableArray *likeArray;
@property (nonatomic, strong) UICollectionView *loverCollectionView;
@property (nonatomic, strong) NSMutableArray *loverArray;
@property (nonatomic, strong) NSArray *secTopArray;

@property (nonatomic, assign) NSInteger page1;
@property (nonatomic, assign) NSInteger page2;
@property (nonatomic, assign) NSInteger page3;
@property (nonatomic, assign) NSInteger page4;

@property (nonatomic, assign) NSInteger sim;

@end

@implementation MasterDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithWhite:0.214 alpha:1.000];
    self.page1 = 1;
    self.page2 = 1;
    self.page3 = 1;
    self.page4 = 1;
    
    self.likeArray = [NSMutableArray array];

    self.indexArray = [NSMutableArray array];
    self.secIdexArray = [NSMutableArray array];
    [self createBackButton];
    self.segArray = [NSArray array];
    [self createTopView];
    
    [self createTopData];
    [self createData];
    [self createLoverData];
    [self createConcernData];
    [self createLikeData];

}
// 粉丝数据
- (void)createLoverData {
      NSDictionary *headDic = @{@"Host": @"mobile.iliangcang.com", @"Proxy-Connection": @"keep-alive", @"Accept": @"*/*", @"Accept-Language": @"zh-Hans-CN;q=1, en-CN;q=0.9", @"Connection": @"keep-alive", @"User-Agent": @"iLiangCang/3.0.0 (iPhone; iOS 9.2.1; Scale/2.00) Paros/3.2.13"};
    NSString *str1 = @"http://mobile.iliangcang.com/user/masterFollowed/?&page=";
    NSString *str3 = @"&owner_id=";
    NSString *str2 = @"&count=10&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981&user_token=03723b5fa4100c1079e788f94d65908d";
    NSString *str = [[[[str1 stringByAppendingString:[NSString stringWithFormat:@"%ld", self.page4]] stringByAppendingString:str3] stringByAppendingString:self.netID] stringByAppendingString:str2];
    [ZWYNetTool GET:str andBody:nil andHeader:headDic andResponse:ZWYJSON andSuccessBlock:^(id result) {
        if (self.page4 == 1) {
            self.loverArray = [NSMutableArray array];
        }
        NSArray *array = result[@"data"][@"items"][@"users"];
        for (NSDictionary *dic in array) {
            LoverModel *lover = [LoverModel modelWithDic:dic];
            [self.loverArray addObject:lover];
        }
        self.page4 = self.page4 + 1;
        NSLog(@"%ld", self.page4);
        [self.loverCollectionView reloadData];

    } andFailureBlock:^(NSError *error) {
    }];
}

- (void)createTopData {
    self.topArray = [NSMutableArray array];
    NSDictionary *headDic = @{@"Host": @"mobile.iliangcang.com", @"Proxy-Connection": @"keep-alive", @"Accept": @"*/*", @"Accept-Language": @"zh-Hans-CN;q=1, en-CN;q=0.9", @"Connection": @"keep-alive", @"User-Agent": @"iLiangCang/3.0.0 (iPhone; iOS 9.2.1; Scale/2.00) Paros/3.2.13"};
    NSString *str1 = @"http://mobile.iliangcang.com/user/masterListInfo/?&page=";
    NSString *str3 = @"&owner_id=";
    NSString *str2 = @"&count=10&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981";
    NSString *str = [[[[str1 stringByAppendingString:[NSString stringWithFormat:@"%ld", self.page1]] stringByAppendingString:str3] stringByAppendingString:self.netID] stringByAppendingString:str2];
    
    [ZWYNetTool GET:str andBody:nil andHeader:headDic andResponse:ZWYJSON andSuccessBlock:^(id result) {
        NSDictionary *dic = result[@"data"][@"items"];
        MasterDetailModel *detail = [MasterDetailModel modelWithDic:dic];
        [self.topArray addObject:detail];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            self.title = [self.topArray[0] user_name];
            [self.picImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [self.topArray[0] user_image][@"orig"]]]];
            self.nameLabel.text = [self.topArray[0] user_name];
            self.jobLabel.text = [self.topArray[0] user_desc];
            
            self.segArray = @[[self.topArray[0] like_count], [self.topArray[0] recommendation_count], [self.topArray[0] following_count], [self.topArray[0] followed_count]];
            [self.topCollectionView reloadData];
        });
    } andFailureBlock:^(NSError *error) {
    }];
}

// 推荐数据
- (void)createData {
   
    NSDictionary *headDic = @{@"Host": @"mobile.iliangcang.com", @"Proxy-Connection": @"keep-alive", @"Accept": @"*/*", @"Accept-Language": @"zh-Hans-CN;q=1, en-CN;q=0.9", @"Connection": @"keep-alive", @"User-Agent": @"iLiangCang/3.0.0 (iPhone; iOS 9.2.1; Scale/2.00) Paros/3.2.13"};
    NSString *str1 = @"http://mobile.iliangcang.com/user/masterListInfo/?&page=";
    NSString *str3 = @"&owner_id=";
    NSString *str2 = @"&count=10&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981";
    NSString *str = [[[[str1 stringByAppendingString:[NSString stringWithFormat:@"%ld", self.page2]] stringByAppendingString:str3] stringByAppendingString:self.netID] stringByAppendingString:str2];

    [ZWYNetTool GET:str andBody:nil andHeader:headDic andResponse:ZWYJSON andSuccessBlock:^(id result) {
        if (self.page2 == 1) {
            self.recommandArray = [NSMutableArray array];
        }
        NSDictionary *dic = result[@"data"][@"items"];
        MasterDetailModel *detail = [MasterDetailModel modelWithDic:dic];
        
        for (NSDictionary *dic in detail.goods) {
            [self.recommandArray addObject:dic];
        }
        self.page2 = self.page2 + 1;
        [self.RecommendCollectionView reloadData];
    } andFailureBlock:^(NSError *error) {
    }];
}
// 关注数据
- (void)createConcernData {
   
    NSDictionary *headDic = @{@"Host": @"mobile.iliangcang.com", @"Proxy-Connection": @"keep-alive", @"Accept": @"*/*", @"Accept-Language": @"zh-Hans-CN;q=1, en-CN;q=0.9", @"Connection": @"keep-alive", @"User-Agent": @"iLiangCang/3.0.0 (iPhone; iOS 9.2.1; Scale/2.00) Paros/3.2.13"};
    NSString *str1 = @"http://mobile.iliangcang.com/user/masterFollow/?&page=";
    NSString *str3 = @"&owner_id=";
    NSString *str2 = @"&count=10&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981";
    NSString *str = [[[[str1 stringByAppendingString:[NSString stringWithFormat:@"%ld", self.page3]] stringByAppendingString:str3] stringByAppendingString:self.netID] stringByAppendingString:str2];
    [ZWYNetTool GET:str andBody:nil andHeader:headDic andResponse:ZWYJSON andSuccessBlock:^(id result) {
        if (self.page3 == 1) {
            self.concernArray = [NSMutableArray array];
        }
        NSArray *array = result[@"data"][@"items"][@"users"];
        for (NSDictionary *dic in array) {
            ConcernModel *concern = [ConcernModel modelWithDic:dic];
            [self.concernArray addObject:concern];
        }
        self.page3 = self.page3 + 1;
        [self.concernCollectionView reloadData];

    } andFailureBlock:^(NSError *error) {
    }];
}
// 喜欢数据
- (void)createLikeData {
    
    NSString *str1 = @"http://mobile.iliangcang.com/user/masterLike/?&page=";
    NSString *str3 = @"&owner_id=";
    NSString *str2 = @"&count=10&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981";
    NSString *str = [[[[str1 stringByAppendingString:[NSString stringWithFormat:@"%ld", self.page1]] stringByAppendingString:str3] stringByAppendingString:self.netID] stringByAppendingString:str2];
    NSDictionary *headDic = @{@"Host": @"mobile.iliangcang.com", @"Proxy-Connection": @"keep-alive", @"Accept": @"*/*", @"Accept-Language": @"zh-Hans-CN;q=1, en-CN;q=0.9", @"Connection": @"keep-alive", @"User-Agent": @"iLiangCang/3.0.0 (iPhone; iOS 9.2.1; Scale/2.00) Paros/3.2.13"};
    [ZWYNetTool GET:str andBody:nil andHeader:headDic andResponse:ZWYJSON andSuccessBlock:^(id result) {
        if (self.page1 == 1) {
            self.likeArray = [NSMutableArray array];
        }
        NSArray *array = result[@"data"][@"items"][@"goods"];
        for (NSDictionary *dic in array) {
            GoodsModel *good = [GoodsModel modelWithDic:dic];
            [self.likeArray addObject:good];
        }
        self.page1 = self.page1 + 1;
        [self.likeCollectionView reloadData];
    } andFailureBlock:^(NSError *error) {
    }];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (self.RecommendCollectionView.contentOffset.y < 0) {
        self.page2 = 1;
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.label.text = NSLocalizedString(@"loading", @"HUD loading title");
        [hud hideAnimated:YES afterDelay:1];
        [self createData];
//        [self.RecommendCollectionView reloadData];
    } else if (self.likeCollectionView.contentOffset.y < 0) {
        self.page1 = 1;
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.label.text = NSLocalizedString(@"loading", @"HUD loading title");
        NSLog(@"下拉刷新");
        [hud hideAnimated:YES afterDelay:1];
        [self createLikeData];
//        [self.likeCollectionView reloadData];
    } else if (self.concernCollectionView.contentOffset.y < 0) {
        self.page3 = 1;
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.label.text = NSLocalizedString(@"loading", @"HUD loading title");
        NSLog(@"下拉刷新");
        [hud hideAnimated:YES afterDelay:1];
        [self createConcernData];
//        [self.concernCollectionView reloadData];
    } else if (self.loverCollectionView.contentOffset.y < 0) {
        self.page4 = 1;
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.label.text = NSLocalizedString(@"loading", @"HUD loading title");
        [hud hideAnimated:YES afterDelay:1];
        [self createLoverData];
//        [self.loverCollectionView reloadData];
    }
}

- (void)upLoad {
    if (self.backScrollView.contentOffset.x == 0) {
        self.likeCollectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
                [self createLikeData];
                [self.likeCollectionView.mj_footer endRefreshing];
        }];
    } else if (self.backScrollView.contentOffset.x == WIDTH) {
        self.RecommendCollectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
                [self createData];
                [self.RecommendCollectionView.mj_footer endRefreshing];
        }];
    } else if (self.backScrollView.contentOffset.x == WIDTH * 2) {
        self.concernCollectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            [self createConcernData];
            [self.concernCollectionView.mj_footer endRefreshing];
        }];
    } else if (self.backScrollView.contentOffset.x == WIDTH * 3) {
        self.loverCollectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            [self createLoverData];
            [self.loverCollectionView.mj_footer endRefreshing];
        }];
    }
}


- (void)createTopView {
    self.topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 150)];
    self.topView.backgroundColor = [UIColor colorWithWhite:0.214 alpha:1.000];
    [self.view addSubview:self.topView];
    
    self.picImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, WIDTH / 4, WIDTH / 4)];

    [self.topView addSubview:self.picImageView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 4 + 10, 5, WIDTH / 4 * 3 - 10, 30)];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.jobLabel.font = [UIFont systemFontOfSize:15];
    [self.topView addSubview:self.nameLabel];
    
    self.jobLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 4 + 10, 40, WIDTH / 4 * 3 - 10, 20)];
    self.jobLabel.textColor = [UIColor lightGrayColor];
    self.jobLabel.font = [UIFont systemFontOfSize:13];
    [self.topView addSubview:self.jobLabel];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((self.view.bounds.size.width - 16) / 4, 40);
    layout.minimumInteritemSpacing = 2;
    layout.minimumLineSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.topCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(5, WIDTH / 4 + 10, WIDTH - 10, 40) collectionViewLayout:layout];
    self.topCollectionView.delegate = self;
    self.topCollectionView.dataSource = self;
    self.topCollectionView.backgroundColor = [UIColor colorWithWhite:0.420 alpha:1.000];
    [self.topView addSubview:self.topCollectionView];
    
    [self.topCollectionView registerClass:[TopCollectionViewCell class] forCellWithReuseIdentifier:@"topReuse"];
    
    self.backScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 155, WIDTH, HEIGHT - 265)];
    self.backScrollView.delegate  = self;
    self.backScrollView.scrollEnabled = NO;
    self.backScrollView.contentSize = CGSizeMake(WIDTH * 4, 0);
    self.backScrollView.pagingEnabled = YES;
    [self.view addSubview:self.backScrollView];
    // 推荐collectionVIew
    UICollectionViewFlowLayout *downLayout = [[UICollectionViewFlowLayout alloc] init];
    downLayout.itemSize = CGSizeMake((WIDTH - 30) / 2, (WIDTH - 30) / 2);
    downLayout.minimumInteritemSpacing = 5;
    downLayout.minimumLineSpacing = 10;
    downLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.RecommendCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT - 265) collectionViewLayout:downLayout];
    self.RecommendCollectionView.backgroundColor = [UIColor colorWithWhite:0.214 alpha:1.000];
    self.RecommendCollectionView.delegate = self;
    self.RecommendCollectionView.dataSource = self;
    [self.backScrollView addSubview:self.RecommendCollectionView];
    
    [self.RecommendCollectionView registerClass:[RecommendCollectionViewCell class] forCellWithReuseIdentifier:@"recommendReuse"];
    // 关注collectionVIew
    UICollectionViewFlowLayout *concernLayout = [[UICollectionViewFlowLayout alloc] init];
    concernLayout.itemSize = CGSizeMake((WIDTH - 45) / 3, (WIDTH - 45) / 3 + 30);
    
    concernLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.concernCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(WIDTH * 2, 0, WIDTH, HEIGHT - 265) collectionViewLayout:concernLayout];
    self.concernCollectionView.delegate = self;
    self.concernCollectionView.dataSource = self;
    self.concernCollectionView.backgroundColor = [UIColor colorWithWhite:0.214 alpha:1.000];
    [self.backScrollView addSubview:self.concernCollectionView];
    
    [self.concernCollectionView registerClass:[LoverCollectionViewCell class] forCellWithReuseIdentifier:@"concernReuse"];
    
    // 喜欢collectionVIew
    UICollectionViewFlowLayout *likeLayout = [[UICollectionViewFlowLayout alloc] init];
    likeLayout.itemSize = CGSizeMake((WIDTH - 30) / 2, (WIDTH - 30) / 2);
    likeLayout.minimumInteritemSpacing = 5;
    likeLayout.minimumLineSpacing = 10;
    likeLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.likeCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 265) collectionViewLayout:likeLayout];
    self.likeCollectionView.backgroundColor = [UIColor colorWithWhite:0.214 alpha:1.000];
    self.likeCollectionView.delegate = self;
    self.likeCollectionView.dataSource = self;
    [self.backScrollView addSubview:self.likeCollectionView];
    
    [self.likeCollectionView registerClass:[RecommendCollectionViewCell class] forCellWithReuseIdentifier:@"secReuse"];
    // 粉丝collectionVIew
    UICollectionViewFlowLayout *loverLayout = [[UICollectionViewFlowLayout alloc] init];
    loverLayout.itemSize = CGSizeMake((WIDTH - 45) / 3, (WIDTH - 45) / 3 + 30);
    loverLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.loverCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(WIDTH * 3, 0, WIDTH, HEIGHT - 265) collectionViewLayout:loverLayout];
    self.loverCollectionView.backgroundColor = [UIColor colorWithWhite:0.214 alpha:1.000];
    self.loverCollectionView.delegate = self;
    self.loverCollectionView.dataSource = self;
    [self.backScrollView addSubview:self.loverCollectionView];

    [self.loverCollectionView registerClass:[LoverCollectionViewCell class] forCellWithReuseIdentifier:@"loverReuse"];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if ([collectionView isEqual:self.RecommendCollectionView]) {
        return self.recommandArray.count;
    } else if ([collectionView isEqual:self.likeCollectionView]) {
        return self.likeArray.count;
    }else if ([collectionView isEqual:self.concernCollectionView]) {
        return self.concernArray.count;
    } else if ([collectionView isEqual:self.loverCollectionView]) {
        return self.loverArray.count;
    } else {
    return self.segArray.count;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    [self upLoad];

    if ([collectionView isEqual:self.topCollectionView]) {
        // 默认选中第一个cell
        TopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"topReuse" forIndexPath:indexPath];
        cell.num = indexPath.row;
        if (indexPath.row == 0) {
            cell.topLabel.textColor = [UIColor blackColor];
            cell.downLabel.textColor = [UIColor blackColor];
            cell.backgroundColor = [UIColor whiteColor];
        } else {
            cell.topLabel.textColor = [UIColor whiteColor];
            cell.downLabel.textColor = [UIColor whiteColor];
            cell.backgroundColor = [UIColor colorWithWhite:0.300 alpha:1.000];
        }
        
        self.topcollectArray = [NSArray array];
        NSString *likeStr = @"喜欢";
        NSString *recommendationStr = @"推荐";
        NSString *followingStr = @"关注";
        NSString *followedStr = @"粉丝";
        [self.indexArray addObject:indexPath];
        self.secIdexArray = self.indexArray;
        
        self.topcollectArray = @[likeStr, recommendationStr,followingStr, followedStr];
        cell.topLabel.text = self.topcollectArray[indexPath.row];
        cell.downLabel.text = self.segArray[indexPath.row];
        
       return cell;
    } else if ([collectionView isEqual:self.likeCollectionView]) {
        // 共用cell
        RecommendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"secReuse" forIndexPath:indexPath];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [self.likeArray[indexPath.row] goods_image]]]];
        return cell;
    } else if ([collectionView isEqual:self.concernCollectionView]) {
        LoverCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"concernReuse" forIndexPath:indexPath];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [self.concernArray[indexPath.row] user_image][@"orig"]]]];
        cell.userLabel.text = [self.concernArray[indexPath.row] user_name];
        return cell;
    } else if ([collectionView isEqual:self.loverCollectionView]) {
        LoverCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"loverReuse" forIndexPath:indexPath];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [self.loverArray[indexPath.row] user_image][@"orig"]]]];
        cell.userLabel.text = [self.loverArray[indexPath.row] user_name];
        return cell;
    } else {
        RecommendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendReuse" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor colorWithWhite:0.165 alpha:1.000];

        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.recommandArray[indexPath.row][@"goods_image"]]]];
        return cell;
    }
  }
// 点击cell改变cell颜色 字体颜色
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([collectionView isEqual:self.topCollectionView]) {
        [self.indexArray removeObject:indexPath];
        TopCollectionViewCell *cell = (TopCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        cell.topLabel.textColor = [UIColor blackColor];
        cell.downLabel.textColor = [UIColor blackColor];
        cell.backgroundColor = [UIColor whiteColor];
        self.backScrollView.contentOffset = CGPointMake(indexPath.row * WIDTH, 0);
        
        for (NSInteger i = 0; i < 3; i++) {
            TopCollectionViewCell *secCell = (TopCollectionViewCell *)[collectionView cellForItemAtIndexPath:self.indexArray[i]];
            secCell.backgroundColor = [UIColor colorWithWhite:0.300 alpha:1.000];
            secCell.topLabel.textColor = [UIColor whiteColor];
            secCell.downLabel.textColor = [UIColor whiteColor];
        }
        [self.indexArray addObject:indexPath];
    } else if ([collectionView isEqual:self.RecommendCollectionView]) {
        // 推荐
        GoodsViewController *goods = [[GoodsViewController alloc] init];
        goods.good_id = self.recommandArray[indexPath.row][@"goods_id"];
        [self.navigationController pushViewController:goods animated:YES];
    } else if ([collectionView isEqual:self.loverCollectionView]) {
        MasterDetailViewController *detailVC = [[MasterDetailViewController alloc] init];
        detailVC.netID = [self.loverArray[indexPath.row] user_id];
        [self.navigationController pushViewController:detailVC animated:YES];
    } else if ([collectionView isEqual:self.concernCollectionView]) {
        MasterDetailViewController *detailVC = [[MasterDetailViewController alloc] init];
        detailVC.netID = [self.concernArray[indexPath.row] user_id];
        [self.navigationController pushViewController:detailVC animated:YES];
    } else if ([collectionView isEqual:self.likeCollectionView]){
        LikeDetailViewController *like = [[LikeDetailViewController alloc] init];
        GoodsModel *good = self.likeArray[indexPath.row];
        like.goodID = good.goods_id;

        [self.navigationController pushViewController:like animated:YES];
    }
}

- (void)createBackButton {
//    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    backButton.frame = CGRectMake(0, 0, 40, 40);
//    [backButton setImage:[UIImage imageNamed:@"25"] forState:UIControlStateNormal];
//    [backButton addTarget:self action:@selector(backClick:)forControlEvents:UIControlEventTouchUpInside];
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    UIButton *left = [TextView createButtonWithImage:[UIImage imageNamed:@"10"]];
    [left addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:left];
}

- (void)backClick:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
